package com.ruoyi.system.service.impl;

import java.nio.channels.SelectionKey;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Transient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.SysDictType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.mapper.SysDictTypeMapper;
import com.ruoyi.system.service.ISysDictTypeService;

/**
 * 字典 业务层处理
 * 
 * @author ruoyi
 */
@Service
public class SysDictTypeServiceImpl implements ISysDictTypeService
{

    @Autowired
    SysDictTypeMapper sysDictTypeMapper;

    @Autowired
    SysDictDataMapper sysDictDataMapper;



    @Override
    public List<SysDictType> selectDictType(SysDictType dictType) {
        return sysDictTypeMapper.selectDictType(dictType);
    }

    @Override
    @Transactional
    public int deleteDictType(Long[] dictId) {
        int cn=0;
        for (Long aLong : dictId) {
            SysDictType sysDictType=sysDictTypeMapper.selectDictId(aLong);
            if (sysDictDataMapper.countDictType(sysDictType.getDictType())>0){
                cn=0;
            }else {

                cn = sysDictTypeMapper.deleteDictType(aLong);
            }
        }
        return cn;
    }

    @Override
    public int insertiDictType(SysDictType sysDictType) {
        return sysDictTypeMapper.insertiDictType(sysDictType);
    }

    @Override
    public SysDictType selectDictDancha(Long dictId) {
        return sysDictTypeMapper.selectDictDancha(dictId);
    }

    @Override
    public int updateDict(SysDictType sysDictType) {
        return sysDictTypeMapper.updateDict(sysDictType);
    }

    @Override
    public int selecDictNameCount(String dictType) {
        return sysDictTypeMapper.selecDictNameCount(dictType);
    }
}
